<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.fick.hibernate.model.*"%>
<%@ page import="com.fick.hibernate.dao.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>河南省公安厅</title>
<link href="images/jiahao.css" rel="stylesheet" type="text/css">
</head>

<body>
<script type="text/javascript">
function CheckForm() {
	var str = document.form.ip.value;
	var strlength = str.length;
	if(strlength==0)
	{
		alert("IP值不能为空");
		document.form.ip.focus();
		return false;
	}
	if(str.indexOf("-")!=-1){
		var ipStrs = str.split("-");
		var result = true;
		for(var n = 0 ; n < ipStrs.length ; n++){
			result = checkIp(n+1,ipStrs[n],ipStrs[n].length);
		}
		return result;
	}
	else {
		return checkIp(1,str,strlength);
	}
}
function checkIp(i,str,strlength){
    var patrn =/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;//正则表达式，\d为数字,{1,3}一位或为三位. 
    if(!patrn.exec(str)){ 
        alert("您输入的第"+i+"个IP格式不正确，必须是000.000.000.000格式"); 
        return false; 
    }
    var laststr; 
        laststr= str.split(".");    //用.把字符串str分开 
        var last_patrn=/^\d{1,3}$/; 
        if(parseInt(laststr[0])>255||parseInt(laststr[1])>255||parseInt(laststr[2])>255||parseInt(laststr[3])>255) //判断IP每位的大小 
        { 
                alert("您输入的第"+i+"个IP范围不正确，每个数字必须是0~255之间"); 
                return false; 
        } 
        if(!last_patrn.exec(laststr[3])) 
        { 
              alert("您输入的第"+i+"个IP格式不正确，必须是000.000.000.000格式"); 
            return false; 
        } 
        return true;
}
</script>
<%
String type=request.getParameter("type");
	IpAllowed ipAllowed = null;
	String ipallowedid = "";
if(type != null && type.equals("1")){
	ipallowedid = request.getParameter("ipallowedid");
	Integer id = Integer.parseInt(ipallowedid);
	IpAllowedDAO ipDao = new IpAllowedDAO();
	ipAllowed = ipDao.findById(id);	
}
%> 
<table width="100%"  height="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="100%" align="center" valign="top" background="images/main_bj.gif" bgcolor="#FBFCFD"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="23" align="left" valign="middle" background="images/main_top.gif"><table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="20" height="23">&nbsp;</td>
            <td width="400" height="23" align="left" valign="middle" class="ts_lmdh2">添加允许IP</td>
          </tr>
        </table></td>
      </tr>
    </table>
      <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="20"></td>
        </tr>
      </table>
<form name="form" id="form" action="addIp.jsp" method="post" onSubmit="return CheckForm()">    	  
<table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
        <tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF">
          IP或IP段：
          <input type="hidden" value="<%=type %>" name="type"/>
          <input type="hidden" value="<%=ipallowedid %>" name="ipallowedid" />
      	  </td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		  <input name="ip"  size="30" value='<%=ipAllowed==null?"":ipAllowed.getIp() %>'  type="text" class="ts_box3"/>
		  (如:10.56.6.31表示某个IP,10.56.6.31-10.56.6.255表示IP段)
		  </td>
        </tr>
        <tr>
          <td width="30%" height="25" align="right" valign="middle" bgcolor="#FFFFFF">备注：</td>
          <td height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		  <input name="remark" id="remark" size="30" value='<%=ipAllowed==null?"":ipAllowed.getRemark() %>'  type="text" class="ts_box3"/>
		  </td>
        </tr>
        <tr>
          <td height="30" colspan="2" align="center" valign="middle" bgcolor="#FFFFFF">
		  <input type="submit" value="提交">
		  <input  type="button" value="返回" onClick="javascript:history.go(-1);">
		  </td>
        </tr>
      </table>
</form>
      <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="45" align="center" valign="middle">&nbsp;</td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
